package com.kakarote.crm9.erp;

import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.activerecord.generator.Generator;
import com.jfinal.plugin.druid.DruidPlugin;
import com.kakarote.crm9.common.config.JfinalConfig;

import javax.sql.DataSource;

/**
 * 本 demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法
 * 详见 JFinal 俱乐部: http://jfinal.com/club
 * 
 * 在数据库表有任何变动时，运行一下 main 方法，极速响应变化进行代码重构
 */
public class _JFinalDemoGenerator {
	
	public  static DataSource getDataSource() {
		DruidPlugin druidPlugin = JfinalConfig.createDruidPlugin();
		druidPlugin.start();
		return druidPlugin.getDataSource();
	}
	
	public  void main(String[] args) {
		// base model 所使用的包名
		String baseModelPackageName = "com.kakarote.crm9.erp.ding.entity.base";
		// base model 文件保存路径
		String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/kakarote/crm9/erp/ding/entity/base";
		
		// model 所使用的包名 (MappingKit 默认使用的包名)
		String modelPackageName = "com.kakarote.crm9.erp.ding.entity";
		// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
		String modelOutputDir = baseModelOutputDir + "/..";
		
		// 创建生成器
		Generator generator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
		
		// 配置是否生成备注
		generator.setGenerateRemarks(true);
		
		// 设置数据库方言
		generator.setDialect(new MysqlDialect());
		
		// 设置是否生成链式 setter 方法
		generator.setGenerateChainSetter(false);
		
		// 添加不需要生成的表名
		generator.addExcludedTable("72crm_admin_config","72crm_admin_customer_setting","72crm_admin_dept","72crm_admin_examine","72crm_admin_examine_log","72crm_admin_examine_record","72crm_admin_examine_step","72crm_admin_field","72crm_admin_field_sort","72crm_admin_field_style","72crm_admin_file","72crm_admin_menu","72crm_admin_record","72crm_admin_role","72crm_admin_role_menu","72crm_admin_scene","72crm_admin_scene_default","72crm_admin_user","72crm_admin_user_role","72crm_crm_achievement","72crm_crm_action_record","72crm_crm_business","72crm_crm_business_product","72crm_crm_business_status","72crm_crm_business_type","72crm_crm_contacts","72crm_crm_contract","72crm_crm_contract_product","72crm_crm_customer","72crm_crm_leads","72crm_crm_product","72crm_crm_product_category","72crm_crm_receivables","72crm_crm_receivables_plan","72crm_oa_action_record","72crm_oa_announcement","72crm_oa_event","72crm_oa_event_notice","72crm_oa_event_relation","72crm_oa_examine","72crm_oa_examine_category","72crm_oa_examine_log","72crm_oa_examine_record","72crm_oa_examine_relation","72crm_oa_examine_step","72crm_oa_examine_travel","72crm_oa_log","72crm_oa_log_relation","72crm_task","72crm_task_comment","72crm_task_relation","72crm_work","72crm_work_relation","72crm_work_task_class","72crm_work_task_lable","72crm_work_task_log","ding_user","ding_config","app_id","ding_alluser","ding_login","ding_token","text_message");

		// 设置是否在 Model 中生成 dao 对象
		generator.setGenerateDaoInModel(false);
		
		// 设置是否生成字典文件
		generator.setGenerateDataDictionary(false);
		
		// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user"，移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
		generator.setRemovedTableNamePrefixes("t_");
		
		// 生成
		generator.generate();
	}
}




